***** Setting up graphical scheme *****
** grstyle+palette package for gray scale
grstyle init
grstyle set imesh, horizontal compact 
grstyle set legend 6, nobox
grstyle set color 538, n(4)

********************************************************************************
************************* APPENDIX A1: Pretest *********************************
********************************************************************************
*** Main data input
import delimited "usa_main.csv", clear varname(1)
mean saudi
	estimates store sa3
mean iran
	estimates store iran3
mean norway
	estimates store nor3
mean russia
	estimates store rus3
mean ven
	estimates store ven3
	
import delimited "can_main.csv", clear varname(1)	
mean saudi
	estimates store sa4
mean iran
	estimates store iran4
mean norway
	estimates store nor4
mean russia
	estimates store rus4
mean ven
	estimates store ven4 

*** Pretest of US and Canadian Data ***

** Input USA pretest data
import delimited "pretest_usa.csv", clear varname(1)

mean plegit_fund
	estimates store funding1
mean plegit_train
	estimates store training1

gen psize = 1 if size==100
replace psize = 2 if size==200
replace psize = 3 if size==300
replace psize = 4 if size==400
replace psize = 5 if size==600
replace psize = 6 if size==700
replace psize = 7 if size==800
replace psize = 8 if size==900
replace psize = 10 if size==1000
replace psize = 11 if size==2000
replace psize = 12 if size==5000
replace psize = 13 if size==50000
replace psize = 14 if size==100000
replace psize = 15 if size==500000
replace psize = 16 if size==1000000
replace psize = 17 if size==2000000
	
proportion psize
	estimates store size1

mean saudi
	estimates store sa1
mean iran
	estimates store iran1
mean norway
	estimates store nor1
mean russia
	estimates store rus1
mean ven
	estimates store ven1
	
	
proportion blm_race1
	estimates store blm	
proportion green_race1
	estimates store green
proportion sierra_race1
	estimates store sierra	
proportion foe_race1
	estimates store foe
proportion naacp_race1
	estimates store naacp	
proportion tribe_race1
	estimates store tribe	
	

mean blm_asian		
estimates store Asian1 
mean blm_black		
estimates store Black1
mean blm_white	
estimates store White1
mean blm_native	
estimates store Native1
mean blm_hispanic	
estimates store Hispanic1

mean naacp_asian		
estimates store Asian2 
mean naacp_black		
estimates store Black2
mean naacp_white	
estimates store White2
mean naacp_native	
estimates store Native2
mean naacp_hispanic	
estimates store Hispanic2

mean green_asian		
estimates store Asian3 
mean green_black		
estimates store Black3
mean green_white	
estimates store White3
mean green_native	
estimates store Native3
mean green_hispanic	
estimates store Hispanic3

mean sierra_asian		
estimates store Asian4 
mean sierra_black		
estimates store Black4
mean sierra_white	
estimates store White4
mean sierra_native	
estimates store Native4
mean sierra_hispanic	
estimates store Hispanic4

mean foe_asian		
estimates store Asian5 
mean foe_black		
estimates store Black5
mean foe_white	
estimates store White5
mean foe_native	
estimates store Native5
mean foe_hispanic	
estimates store Hispanic5

mean tribe_asian		
estimates store Asian6 
mean tribe_black		
estimates store Black6
mean tribe_white	
estimates store White6
mean tribe_native	
estimates store Native6
mean tribe_hispanic	
estimates store Hispanic6
	
	
** Input Canada pretest data
import delimited "pretest_can.csv", clear varname(1)
	
mean plegit_1
	estimates store funding2
mean plegit_2
	estimates store training2

proportion psize
	estimates store size2

mean saudi
	 estimates store sa2
mean norway
	 estimates store nor2
mean russia
	 estimates store rus2
mean iran
	 estimates store iran2
mean ven
	 estimates store ven2
	 
proportion group1_1	 
	estimates store group1
proportion group1_2
	estimates store group2
proportion group1_3	 
	estimates store group3
proportion group1_4	 
	estimates store group4
proportion group1_5	 
	estimates store group5
proportion group1_6	 
	estimates store group6
	
mean race1_1_1
	estimates store edc1
mean race1_1_2
	estimates store edc2
mean race1_1_3
	estimates store edc3
mean race1_1_4
	estimates store edc4
mean race1_1_5
	estimates store edc5	
mean race1_2_1
	estimates store mnc1
mean race1_2_2
	estimates store mnc2
mean race1_2_3
	estimates store mnc3
mean race1_2_4
	estimates store mnc4
mean race1_2_5
	estimates store mnc5
mean race1_3_1
	estimates store nature1
mean race1_3_2
	estimates store nature2
mean race1_3_3
	estimates store nature3
mean race1_3_4
	estimates store nature4
mean race1_3_5
	estimates store nature5
mean race2_1_1
	estimates store afn1
mean race2_1_2
	estimates store afn2
mean race2_1_3
	estimates store afn3
mean race2_1_4
	estimates store afn4
mean race2_1_5
	estimates store afn5	
mean race2_2_1
	estimates store gp1
mean race2_2_2
	estimates store gp2
mean race2_2_3
	estimates store gp3
mean race2_2_4
	estimates store gp4
mean race2_2_5
	estimates store gp5	
mean race2_3_1
	estimates store inm1
mean race2_3_2
	estimates store inm2
mean race2_3_3
	estimates store inm3
mean race2_3_4
	estimates store inm4
mean race2_3_5
	estimates store inm5			
	
	

********************************************************************************	 
** FIGURE A1.1: PROTEST SIZE CONSIDERED AS SIGNIFICANT SUPPORT *****************
********************************************************************************

coefplot size1 size2, vertical recast(bar) barwidth(.25) noci ///
	 xlabel(1 "100" 2 "200" 3 "300" 4 "400" 5 "500" 6 "700" 7 "800" ///
			8 "900" 9 "1,000" 10 "2,000" 11 "5,000" 12 "10,000" ///
			13 "50,000" 14 "100,000" 15 "500,000" 16 "1,000,000" ///
			17 "1,000,000+", ///
			angle(45)) rescale(100) format(%9.0f)  color(*.75) ///
	 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(12) mlabcolor(black)) ///
	 ytitle("Percent") legend(order(1 "USA" 2 "Canada")) ///
	 xtitle("Number of Protesters Needed to be Considered Significant")

********************************************************************************	 
* FIGURE A1.2: SINGLE CHOICE COMMON RACIAL CATEGORY BY PROTEST GROUP ***********
********************************************************************************	 

*** USA
coefplot blm, bylabel("Black Lives Matter") || ///
		 green, bylabel("Greenpeace") || ///
		 sierra, bylabel("Sierra Club") || ///
		 foe, bylabel("Friends of the Earth") || ///
		 naacp, bylabel("NAACP") || ///
		 tribe, bylabel("Native American Group") rescale(100) ///
	 vertical recast(bar) format(%9.0f) noci color(538b*.75) barwidth(.75) ///
	 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
	 ytitle("Racial/Ethnic Percentage") ///
	 xtitle("Racial Distribution Based on Most Common Racial/Ethnic Group") ///
	 xlabel(1 "Black" 2 "Asian" 3 "White" 4 "Hispanic" ///
	  5 `""Native" "American""') legend(off) ylabel(0(20)100) scale(1.2) ///
	 name(race_usa1, replace) 

*** Canada
coefplot group1, bylabel("Indigenous Group 1") || ///
		 group2, bylabel("Indigenous Group 3") || ///
		 group3, bylabel("Greenpeace") || ///
		 group4, bylabel("Nature Canada") || ///
		 group5, bylabel("Indigenous Group 2") || ///
		 group6, bylabel("Environmental Defence Canada") rescale(100) ///
	 vertical recast(bar) format(%9.0f) noci color(538r*.75) barwidth(.75) ///
	 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
	 ytitle("Racial/Ethnic Percentage") ///
	 xtitle("Racial Distribution Based on Most Common Racial/Ethnic Group") ///
	 xlabel(1 `""East" "Asian""' 2 "White" 3 "Indigenous" 4 ///
	 "Black" 5 `""South" "Asian""') legend(off) ylabel(0(20)100) scale(1.2) ///
	 name(race_usa2, replace)

*** Combine graphs
graph combine race_usa1 race_usa2, ///
			   cols(1) xsize(10) ysize(8)
	 
********************************************************************************	 
* FIGURE A1.3: PERCEIVED RACIAL DISTRIBUTION OF PROTEST GROUPS *******************
********************************************************************************
*** USA

coefplot Black1 Asian1 White1 Hispanic1 Native1, ///
		 vertical noci recast(bar) color(538b*.80) ///
		 xlabel(.7 "Black" 1.9 "Asian" 3 "White" ///
		 4.2 "Hispanic" 5.35 `" "Native" "American" "') ///
		 ytitle("Racial/Ethnic %")  format(%9.0f) ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 legend(off) title("Black Lives Matter") name(blm, replace)
	 
coefplot Black2 Asian2 White2 Hispanic2 Native2, ///
		 vertical noci recast(bar) color(538b*.80) ///
		 xlabel(.7 "Black" 1.9 "Asian" 3 "White" ///
		 4.2 "Hispanic" 5.35 `" "Native" "American" "') ///
		 ytitle("Racial/Ethnic %")  format(%9.0f) ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 legend(off) title("NAACP") name(naacp, replace)

coefplot Black3 Asian3 White3 Hispanic3 Native3, ///
		 vertical noci recast(bar) color(538b*.80) ///
		 xlabel(.7 "Black" 1.9 "Asian" 3 "White" ///
		 4.2 "Hispanic" 5.35 `" "Native" "American" "') ///
		 ytitle("Racial/Ethnic %") format(%9.0f)  ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 legend(off) title("Greenpeace") name(green, replace)

coefplot Black4 Asian4 White4 Hispanic4 Native4, ///
		 vertical noci recast(bar) color(538b*.80) ///
		 xlabel(.7 "Black" 1.9 "Asian" 3 "White" ///
		 4.2 "Hispanic" 5.35 `" "Native" "American" "') ///
		 ytitle("Racial/Ethnic %") format(%9.0f)  ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 legend(off) title("Sierra Club") name(sierra, replace)

coefplot Black5 Asian5 White5 Hispanic5 Native5, ///
		 vertical noci recast(bar) color(538b*.80) ///
		 xlabel(.7 "Black" 1.9 "Asian" 3 "White" ///
		 4.2 "Hispanic" 5.35 `" "Native" "American" "') ///
		 ytitle("Racial/Ethnic %")  format(%9.0f) ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 legend(off) title("Friends of the Earth") name(foe, replace)

coefplot Black6 Asian6 White6 Hispanic6 Native6, ///
		 vertical noci recast(bar) color(538b*.80) ///
		 xlabel(.7 "Black" 1.9 "Asian" 3 "White" ///
		 4.2 "Hispanic" 5.35 `" "Native" "American" "') ///
		 ytitle("Racial/Ethnic %") format(%9.0f) ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 legend(off) title("Native American Group") name(tribe, replace)

graph combine blm naacp tribe green sierra foe, ///
			  xcommon ycommon title("U.S. Pretest Racial Groups") ///
			  name(race_usa1, replace)
	
	 
*** Canada	 
coefplot edc1 edc2 edc3 edc4 edc5, ///		
	 vertical recast(bar) color(538r*.80) format(%9.0f) noci ///
	 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
	 ytitle("Racial/Ethnic %") xtitle("") ///
	 xlabel(1 `""East" "Asian""' 2 `""First" "Nations""' 3 `""South" "Asian""' ///
	 4 "White" 5 "Black") legend(off) ylabel(0(20)100) legend(off) ///
	 title("Environmental Defence Canada") ///
	 name(graph1, replace)
	 
 coefplot mnc1 mnc2 mnc3 mnc4 mnc5, ///
 	 vertical recast(bar) color(538r*.80) format(%9.0f) noci ///
	 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
	 ytitle("Racial/Ethnic %") xtitle("") ///
	 xlabel(1 `""East" "Asian""' 2 `""First" "Nations""' 3 `""South" "Asian""' ///
	 4 "White" 5 "Black") legend(off) ylabel(0(20)100) legend(off) ///
	 title("Indigenous Group 2") ///
	 name(graph2, replace)
 
coefplot nature1 nature2 nature3 nature4 nature5, ///
	 vertical recast(bar) color(538r*.80) format(%9.0f) noci ///
	 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
	 ytitle("Racial/Ethnic %") xtitle("") ///
	 xlabel(1 `""East" "Asian""' 2 `""First" "Nations""' 3 `""South" "Asian""' ///
	 4 "White" 5 "Black") legend(off) ylabel(0(20)100) legend(off) ///
	 title("Nature Canada") ///
	 name(graph3, replace)
	 
coefplot afn1 afn2 afn3 afn4 afn5, ///
	 vertical recast(bar) color(538r*.80) format(%9.0f) noci ///
	 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
	 ytitle("Racial/Ethnic %") xtitle("") ///
	 xlabel(1 `""East" "Asian""' 2 `""First" "Nations""' 3 `""South" "Asian""' ///
	 4 "White" 5 "Black") legend(off) ylabel(0(20)100) legend(off) ///
	 title("Indigenous Group 1") ///
	 name(graph4, replace)
	 
coefplot gp1 gp2 gp3 gp4 gp5, ///
	 vertical recast(bar) color(538r*.80) format(%9.0f) noci ///
	 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
	 ytitle("Racial/Ethnic %") xtitle("") ///
	 xlabel(1 `""East" "Asian""' 2 `""First" "Nations""' 3 `""South" "Asian""' ///
	 4 "White" 5 "Black") legend(off) ylabel(0(20)100) legend(off) ///
	 title("Greenpeace Canada") ///
	 name(graph5, replace)
	 
coefplot inm1 inm2 inm3 inm4 inm5, ///
	 vertical recast(bar) color(538r*.80) format(%9.0f) noci ///
	 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
	 ytitle("Racial/Ethnic %") xtitle("") ///
	 xlabel(1 `""East" "Asian""' 2 `""First" "Nations""' 3 `""South" "Asian""' ///
	 4 "White" 5 "Black") legend(off) ylabel(0(20)100) legend(off) ///
	 title("Indigenous Group 3") name(graph6, replace)

graph combine graph1 graph2 graph3 graph4 graph5 graph6, ///
			  xcommon ycommon title("Canada Pretest Racial Groups") ///
			  name(race_can1, replace)


*** Combined graph

graph combine race_usa1 race_can1, cols(1) xsize(7) ysize(8)

********************************************************************************	 
* FIGURE A1.4: COUNTRY FAVORABILITY RATING COMPARISONS ***************************
********************************************************************************			  

** Input pretest data
import delimited "pretest_usa.csv", clear varname(1)
mean saudi
	estimates store sa1
mean iran
	estimates store iran1
mean norway
	estimates store nor1
mean russia
	estimates store rus1
mean ven
	estimates store ven1

** Input Canada pretest data
import delimited "pretest_can.csv", clear varname(1)
	
mean saudi
	 estimates store sa2
mean norway
	 estimates store nor2
mean russia
	 estimates store rus2
mean iran
	 estimates store iran2
mean ven
	 estimates store ven2

** pretest samples
coefplot (sa1, color(538b*.8)) (sa2, color(538r*.8)), ///		 
	     recast(bar) vertical format(%9.2g) barwidth(.33) ///
		 xlabel(1 "Saudi Arabia") ylabel("") ///
		 legend(order(1 "USA" 3 "Canada")) color(*.75) ///
		 ciopts(recast(rcap) lcolor(black)) citop ///
		 title("Pretest Surveys") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 name(pre1a, replace)

coefplot (iran1, color(538b*.8)) (iran2, color(538r*.8)), ///		 
	     recast(bar) vertical format(%9.2g) barwidth(.33) ///
		 xlabel(1 "Iran") color(*.75) ylabel("") ///
		 ciopts(recast(rcap) lcolor(black)) citop ///
		 title("Pretest Surveys") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 name(pre1b, replace)

coefplot (rus1, color(538b*.8)) (rus2, color(538r*.8)), ///		 
	     recast(bar) vertical format(%9.2g) barwidth(.33) ///
		 xlabel(1 "Russia") color(*.75) ylabel("") ///
		 ciopts(recast(rcap) lcolor(black)) citop ///
		 title("Pretest Surveys") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 name(pre1c, replace)

coefplot (ven1, color(538b*.8)) (ven2, color(538r*.8)), ///		 
	     recast(bar) vertical format(%9.2g) barwidth(.33) ///
		 xlabel(1 "Venezuela") color(*.75) ylabel("") ///
		 ciopts(recast(rcap) lcolor(black)) citop ///
		 title("Pretest Surveys") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 name(pre1d, replace)

coefplot (nor1, color(538b*.8)) (nor2, color(538r*.8)), ///		 
	     recast(bar) vertical format(%9.2g) barwidth(.33) ///
		 xlabel(1 "Norway") color(*.75) ylabel("") ///
		 ciopts(recast(rcap) lcolor(black)) citop ///
		 title("Pretest Surveys") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 name(pre1e, replace)

** main survey samples
*** Main data input
import delimited "usa_main.csv", clear varname(1)
mean saudi
	estimates store sa3
mean iran
	estimates store iran3
mean norway
	estimates store nor3
mean russia
	estimates store rus3
mean ven
	estimates store ven3
	
import delimited "can_main.csv", clear varname(1)	
mean saudi
	estimates store sa4
mean iran
	estimates store iran4
mean norway
	estimates store nor4
mean russia
	estimates store rus4
mean ven
	estimates store ven4 

** pretest samples
coefplot (sa3, color(538b*.8)) (sa4, color(538r*.8)), ///		 
	     recast(bar) vertical format(%9.2g) barwidth(.33) ///
		 xlabel(1 "Saudi Arabia") ylabel("") ///
		 legend(order(1 "USA" 3 "Canada")) color(*.75) ///
		 ciopts(recast(rcap) lcolor(black)) citop ///
		 title("Main Surveys") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 name(pre2a, replace)

coefplot (iran3, color(538b*.8)) (iran4, color(538r*.8)), ///		 
	     recast(bar) vertical format(%9.2g) barwidth(.33) ///
		 xlabel(1 "Iran") color(*.75) ylabel("") ///
		 ciopts(recast(rcap) lcolor(black)) citop ///
		 title("Main Surveys") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 name(pre2b, replace)

coefplot (rus3, color(538b*.8)) (rus4, color(538r*.8)), ///		 
	     recast(bar) vertical format(%9.2g) barwidth(.33) ///
		 xlabel(1 "Russia") color(*.75) ylabel("") ///
		 ciopts(recast(rcap) lcolor(black)) citop ///
		 title("Main Surveys") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 name(pre2c, replace)

coefplot (ven3, color(538b*.8)) (ven4, color(538r*.8)), ///		 
	     recast(bar) vertical format(%9.2g) barwidth(.33) ///
		 xlabel(1 "Venezuela") color(*.75) ylabel("") ///
		 ciopts(recast(rcap) lcolor(black)) citop ///
		 title("Main Surveys") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 name(pre2d, replace)

coefplot (nor3, color(538b*.8)) (nor4, color(538r*.8)), ///		 
	     recast(bar) vertical format(%9.2g) barwidth(.33) ///
		 xlabel(1 "Norway") color(*.75) ylabel("") ///
		 ciopts(recast(rcap) lcolor(black)) citop ///
		 title("Main Surveys") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 name(pre2e, replace)

*** Combine figures to complete Figure A1.4
grc1leg2 pre1a pre1b pre1c pre1d pre1e pre2a pre2b pre2c pre2d pre2e, ///
		 xcommon ycommon rows(2) scale(1.2) ///
		 legendfrom(pre2a) margins(0 0 0 0) ///
		 l1title("Mean Favorability Rating", size(small)) lrows(1)
		 
				 
********************************************************************************	 
* FIGURE A1.5: Types of Foreign Interference Support *****************************
********************************************************************************

coefplot (funding1, color(538b*.8)) (training1, color(538b*.8)), /// 
		 recast(bar) vertical format(%9.2f) barwidth(.9) ///
		 xlabel(1 "Financial Aid" 2 "Training Aid") ///
		 legend(order(1 "USA")) color(*.75) ///
		 ciopts(recast(rcap) lcolor(black)) citop ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 ytitle("Mean Legitimacy") name(ptype1, replace)
		 
coefplot (funding2, color(538r*.8)) (training2, color(538r*.8)), ///
		 recast(bar) vertical format(%9.2f) barwidth(.9) ///
		 xlabel(1 "Financial Aid" 2 "Training Aid") ///
		 legend(order(1 "Canada")) color(*.75) ///
		 ciopts(recast(rcap) lcolor(black)) citop ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(1) mlabcolor(black)) ///
		 ytitle("Mean Legitimacy") name(ptype2, replace)

graph combine ptype1 ptype2
		 
				 
********************************************************************************
************** Appendix A2: Survey Sample Demographics *************************
********************************************************************************


********************************************************************************	 
** Table A2.1: PROTEST SIZE CONSIDERED AS SIGNIFICANT SUPPORT *****************
********************************************************************************

*** US table: Survey Sample Characteristics (U.S.)
import delimited "usa_main.csv", clear varname(1)

quietly tabout female age race region using "sum_us.csv", ptotal(none) ///
	   oneway cells(col) clab(USA) style(csv) format(2) replace
	   
*** Canada Table: Survey Sample Characteristics (Canada)
import delimited "can_main.csv", clear varname(1)

gen race1 = "White" if race==1
	replace race1 = "East Asian" if race==2
	replace race1 = "Indigenous" if race==3
	replace race1 = "Black/Middle Eastern/Other" if race==6 | race==4
	replace race1 = "South Asian" if race==5
	
quietly tabout female age race1 province using "sum_can.csv", ptotal(none) ///
	   oneway cells(col) clab(Canada) style(csv) format(2) replace	   	 
	   
	   
********************************************************************************	 
***** Figure A2.1: Power Tests for Sample Size Selection ***********************
********************************************************************************

* Locate sample means for determination of power test at power level of .80
import delimited "usa_main.csv", clear varname(1)
sum concede if intervene==0
** mean = 3.473 sd = 1.379
sum concede if intervene==1
** mean = 3.261 sd = 1.453
sum repress if intervene==0
** mean = 3.307 sd = 1.453
sum repress if intervene==1
** mean = 3.565 sd = 1.377

import delimited "can_main.csv", clear varname(1)
sum concede if intervene==0
** mean = 3.103 sd = 1.403
sum concede if intervene==1
** mean = 2.905 sd = 1.418
sum repress if intervene==0
** mean = 3.236 sd = 1.381
sum repress if intervene==1
** mean = 3.571 sd = 1.304


* US Data
power twomeans 3.475 (3.264), ///
	  n(200 400 600 800 1000 1200 1400 1600)  sd1(1.379) ///
	  sd2(1.453) graph(scheme(plottig) title("(a) Concede to Protesters"))
graph save "power_us1.gph", replace 	  

power twomeans 3.302 (3.562), ///
	  n(200 400 600 800 1000 1200 1400 1600)  sd1(1.454) ///
	  sd2(1.378) graph(scheme(plottig) title("(b) Repress Protesters"))
graph save "power_us2.gph", replace 

graph combine "power_us1.gph" "power_us2.gph", ///
	  title("U.S. Survey Power Test", size(medium)) name(us_power, replace)
	  
* Canadian Data
power twomeans 3.103 (2.905), ///
	  n(200 400 600 800 1000 1200 1400 1600)  sd1(1.403) ///
	  sd2(1.418) graph(scheme(plottig) title("(c) Concede to Protesters"))
graph save "power_can1.gph", replace 	  

power twomeans 3.236 (3.571), ///
	  n(200 400 600 800 1000 1200 1400 1600)  sd1(1.381) ///
	  sd2(1.304) graph(scheme(plottig) title("(d) Repress Protesters"))
graph save "power_can2.gph", replace 

graph combine "power_can1.gph" "power_can2.gph", ///
	  title("Canada Survey Power Test", size(medium)) name(can_power, replace)	  

* Generate Figure   
graph combine us_power can_power, rows(2) scale(1.2) xsize(7) ysize(5)
	  
	  
********************************************************************************	  
*** Figure A2.2: Treatment Distribution for U.S./Canadian Sample Data **********
********************************************************************************

/* Note this figure is constructed using powerpoint, but the table information is 
drawn from Tables A2.3a to A2.3e with the exception of the upper two boxes (no 
interference and foreign intelligence confidence) and middle two boxees (financial
aid or training | before and financial aid or training | after). For the top of 
the figure, we use the tab script results from Stata (see code and results below). */

import delimited "usa_main.csv", clear varname(1)
	label define group 0 "No Interference" 1 "Interference 75%" ///
					   2 "Interference 100%" 
	label values intel group
	tab intel 
	
/*
      intel |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |        861       33.59       33.59
          1 |        853       33.28       66.87
          2 |        849       33.13      100.00
------------+-----------------------------------
      Total |      2,563      100.00

*/					

import delimited "can_main.csv", clear varname(1)
	label define group 0 "No Interference" 1 "Interference 75%" ///
					   2 "Interference 100%" 
	label values intel group
	tab intel 

/*
            intel |      Freq.     Percent        Cum.
------------------+-----------------------------------
  No Interference |        889       33.37       33.37
 Interference 75% |        885       33.22       66.59
Interference 100% |        890       33.41      100.00
------------------+-----------------------------------
            Total |      2,664      100.00
*/			

import delimited "usa_main.csv", clear varname(1)
	label define group1 1 "Before (both support types)" ///
						2 "After (both support types)" 				   
	label values timing group1
	tab timing if intervene==1		
	
/*	
                     timing |      Freq.     Percent        Cum.
----------------------------+-----------------------------------
Before (both support types) |        825       48.47       48.47
 After (both support types) |        877       51.53      100.00
----------------------------+-----------------------------------
                      Total |      1,702      100.00
*/
  
import delimited "can_main.csv", clear varname(1)
	label define group1 1 "Before (both support types)" ///
						2 "After (both support types)" 				   
	label values timing group1
	tab timing if intervene==1		

/*

                     timing |      Freq.     Percent        Cum.
----------------------------+-----------------------------------
Before (both support types) |        900       50.70       50.70
 After (both support types) |        875       49.30      100.00
----------------------------+-----------------------------------
                      Total |      1,775      100.00
*/

********************************************************************************	  
*** Tables A2.3a  to A2.3e: ****************************************************
********************************************************************************


*** Table A2.3a: No Interference	   
import delimited "usa_main.csv", clear varname(1)

label define group 0 "Greenpeace" 1 "BLM" ///
				   2 "NAACP" 3 "Sierra Club" 
label values pgroup group		

tabout pgroup using "tableA2.2a.csv" if intervene==0, ///
	cells(freq) style(csv) format(2) ///
	clab("US") replace
	
import delimited "can_main.csv", clear varname(1)
label define group 1 "Greenpeace" 2 "Nature Canada" ///
				   3 "Indigenous Group 1" 4 "Indigenous Group 2" 
label values pgroup group				   

tabout pgroup using "tableA2.2a.csv" if intervene==0, ///
	cells(freq) style(csv) format(2) ///
	clab("Canada") append 


*** Table A2.3b: Foreign Interference	   
import delimited "usa_main.csv", clear varname(1)	
gen pgroups1 = 1 if pgroups==0
	replace pgroups1=2 if pgroups==3
	replace pgroups1=3 if pgroups==1
	replace pgroups1=4 if pgroups==2
drop pgroups
rename pgroups1 pgroups

label define group 1 "Greenpeace" 2 "Sierra Club" 3 "BLM" 4 "NAACP" 
label values pgroup group

tabout pgroup foreign using "tableA2.2b.csv" if intervene==1 ///
	& timing==1 & support==1, cells(freq) style(csv) format(2) ///
	clab("US") ///
	h1(Financial Aid and Before) ///
	h2(| Norway | Russia | Saudi Arabia) replace	         

import delimited "can_main.csv", clear varname(1)

label define group 1 "Greenpeace" 2 "Nature Canada" ///
				   3 "Indigenous Group 1" 4 "Indigenous Group 2" 
label values pgroup group	
		
tabout pgroup foreign using "tableA2.2b.csv" if intervene==1 ///
	& timing==1 & support==1, cells(freq) style(csv) format(2) ///
	clab("Canada") ///
	h1(Financial Aid and Before) ///
	h2(| Norway | Russia | Saudi Arabia) append	         	
	
* Table A2.3c: Foreign Interference	
import delimited "usa_main.csv", clear varname(1)	 
gen pgroups1 = 1 if pgroups==0
	replace pgroups1=2 if pgroups==3
	replace pgroups1=3 if pgroups==1
	replace pgroups1=4 if pgroups==2
drop pgroups
rename pgroups1 pgroups

label define group 1 "Greenpeace" 2 "Sierra Club" 3 "BLM" 4 "NAACP" 
label values pgroup group
	
tabout pgroup foreign using "tableA2.2c.csv" if intervene==1 ///
	& timing==1 & support==2, clab("US") ///
	cells(freq) style(csv) format(2) h1(Training Aid and Before) ///
	h2(| Norway | Russia | Saudi Arabia) replace		
	
import delimited "can_main.csv", clear varname(1)
label define group 1 "Greenpeace" 2 "Nature Canada" ///
				   3 "Indigenous Group 1" 4 "Indigenous Group 2" 
label values pgroup group	
		
tabout pgroup foreign using "tableA2.2c.csv" if intervene==1 ///
	& timing==1 & support==2, cells(freq) style(csv) format(2) ///
	clab("Canada") ///
	h1(Training Aid and Before) ///
	h2(| Norway | Russia | Saudi Arabia) append	
	   
* Table A2.3d: Foreign Interference	 
import delimited "usa_main.csv", clear varname(1)	
gen pgroups1 = 1 if pgroups==0
	replace pgroups1=2 if pgroups==3
	replace pgroups1=3 if pgroups==1
	replace pgroups1=4 if pgroups==2
drop pgroups
rename pgroups1 pgroups

label define group 1 "Greenpeace" 2 "Sierra Club" 3 "BLM" 4 "NAACP" 
label values pgroup group
	   
tabout pgroup foreign using "tableA2.2d.csv" if intervene==1 ///
	& timing==2 & support==1, clab("US") ///
	cells(freq) style(csv) format(2) h1(Financial Aid and After) ///
	h2(| Norway | Russia | Saudi Arabia) replace	         

import delimited "can_main.csv", clear varname(1)

label define group 1 "Greenpeace" 2 "Nature Canada" ///
				   3 "Indigenous Group 1" 4 "Indigenous Group 2" 
label values pgroup group	
				
tabout pgroup foreign using "tableA2.2d.csv" if intervene==1 ///
	& timing==2 & support==1, cells(freq) style(csv) format(2) ///
	clab("Canada") ///
	h1(Financial Aid and Before) ///
	h2(| Norway | Russia | Saudi Arabia) append
	
* Table A2.3e: Foreign Interference	
import delimited "usa_main.csv", clear varname(1)	
gen pgroups1 = 1 if pgroups==0
	replace pgroups1=2 if pgroups==3
	replace pgroups1=3 if pgroups==1
	replace pgroups1=4 if pgroups==2
drop pgroups
rename pgroups1 pgroups

label define group 1 "Greenpeace" 2 "Sierra Club" 3 "BLM" 4 "NAACP" 
label values pgroup group
 	
tabout pgroup foreign using "tableA2.2e.csv" if intervene==1 ///
	& timing==2 & support==2, clab("US") ///
	cells(freq) style(csv) format(2) h1(Training Aid and After) ///
	h2(| Norway | Russia | Saudi Arabia) replace	   

import delimited "can_main.csv", clear varname(1)

label define group 1 "Greenpeace" 2 "Nature Canada" ///
				   3 "Indigenous Group 1" 4 "Indigenous Group 2"  
label values pgroup group	
				
tabout pgroup foreign using "tableA2.2e.csv" if intervene==1 ///
	& timing==2 & support==2, cells(freq) style(csv) format(2) ///
	clab("Canada") ///
	h1(Financial Aid and Before) ///
	h2(| Norway | Russia | Saudi Arabia) append	
	
					
********************************************************************************
*********************** A4: Heterogenuous Effects ******************************
********************************************************************************

*** Figure A4.1: Heterogenuous Marginal Treatment Effects (Concede)

** Environmentalism
import delimited "usa_main.csv", clear varname(1)
** Calculate percentile values
_pctile environment, p(20)
	return list				/* -0.791 */
_pctile environment, p(40)
	return list 			/* -0.136 */
_pctile environment, p(60)
	return list				/* 0.399 */
_pctile environment, p(80)
	return list				/* 1.034 */


quietly ologit concede i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=-.791) post
	estimates store usa1
quietly ologit concede i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=-.136) post
	estimates store usa2				
quietly ologit concede i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=.399) post
	estimates store usa3
quietly ologit concede i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=1.034) post
	estimates store usa4	
	
import delimited "can_main.csv", clear varname(1)	
** Calculate percentile values
_pctile environment, p(20)
	return list				/* -0.893 */
_pctile environment, p(40)
	return list 			/* -0.09 */
_pctile environment, p(60)
	return list				/* 0.471 */
_pctile environment, p(80)
	return list				/* 0.91 */

quietly ologit concede i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=-.893) post
	estimates store can1
quietly ologit concede i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=-.09) post
	estimates store can2		
quietly ologit concede i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=.471) post
	estimates store can3
quietly ologit concede i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=.91) post
	estimates store can4			
			
coefplot usa1 can1, ///
	vertical ciopts(recast(rcap)) ///
	title("(a) Environmentalism" "20th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	legend(order(2 "USA" 4 "Canada")) ///
	mlabel format(%9.0f) mlabcol(black) mlabpos(1) rescale(100) ///
	name(env1, replace)

coefplot usa2 can2, ///
	vertical ciopts(recast(rcap)) ///
	title("(b) Environmentalism" "40th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) rescale(100) legend(off) ///
	name(env2, replace)

coefplot usa3 can3, ///
	vertical ciopts(recast(rcap)) ///
	title("(c) Environmentalism" "60th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) rescale(100) legend(off) ///
	name(env3, replace)

coefplot usa4 can4, ///
	vertical ciopts(recast(rcap)) ///
	title("(d) Environmentalism" "80th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
	mlabel format(%9.0f) mlabcol(black) mlabpos(1) rescale(100) ///
	name(env4, replace)


** Graph Combine	
grc1leg2 env1 env2 env3 env4, ///
		 xcommon ycommon rows(1) legendfrom(env1) position(12) ///
		 name(environmentalism, replace) ///
		 b1title("Predicted Respondent Outcome (concede)", size(small)) ///
		 l1title("Average Marginal Treatment" ///
				 "Effect of Foreign Interference", size(small))  fysize(53)
		 
**** Nationalism
import delimited "usa_main.csv", clear varname(1)
** Calculate percentile values
_pctile nationalism, p(20)
	return list				/* -0.823 */
_pctile nationalism, p(40)
	return list 			/* -0.132 */
_pctile nationalism, p(60)
	return list				/* 0.524 */
_pctile nationalism, p(80)
	return list				/* 0.869 */

quietly ologit concede i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=-.823) post
	estimates store usa1
quietly ologit concede i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=-.132) post
	estimates store usa2				
quietly ologit concede i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=.524) post
	estimates store usa3
quietly ologit concede i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=0.869) post
	estimates store usa4	
	
import delimited "can_main.csv", clear varname(1)
** Calculate percentile values
_pctile nationalism, p(20)
	return list				/* -0.552 */
_pctile nationalism, p(40)
	return list 			/* -0.085 */
_pctile nationalism, p(60)
	return list				/* 0.564 */
_pctile nationalism, p(80)
	return list				/* 0.849 */
	
quietly ologit concede i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=-.552) post
	estimates store can1
quietly ologit concede i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=-.085) post
	estimates store can2		
quietly ologit concede i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=.564) post
	estimates store can3
quietly ologit concede i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=.849) post
	estimates store can4			
			
coefplot usa1 can1, ///
	vertical ciopts(recast(rcap)) ///
	title("(e) Nationalism" "20th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
	mlabel format(%9.0f) mlabcol(black) mlabpos(1) rescale(100) ///
	name(nat1, replace)

coefplot usa2 can2, ///
	vertical ciopts(recast(rcap)) ///
	title("(f) Nationalism" "40th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') rescale(100)  ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
	name(nat2, replace)

coefplot usa3 can3, ///
	vertical ciopts(recast(rcap)) ///
	title("(g) Nationalism" "60th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') rescale(100) ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
	name(nat3, replace)


coefplot usa4 can4, ///
	vertical ciopts(recast(rcap)) ///
	title("(h) Nationalism" "80th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
	mlabel format(%9.0f) mlabcol(black) mlabpos(1) rescale(100) ///
	name(nat4, replace)


** Graph Combine	
graph combine nat1 nat2 nat3 nat4, ///
		 xcommon rows(1) ycommon ///
		 name(nationalism, replace) ///
		 b1title("Predicted Respondent Outcome (concede)", size(small)) ///
		 l1title("Average Marginal Treatment" ///
				 "Effect of Foreign Interference", size(small)) fysize(47)
		 
graph combine environmentalism nationalism, rows(2) 	  
		   
*** Table A4.1

import delimited "usa_main.csv", clear varname(1)
quietly ologit concede i.intervene##c.environment, robust		   
	estimates store usat_env1
quietly ologit concede i.intervene##c.nationalism, robust		   
	estimates store usat_nat1
quietly ologit repress i.intervene##c.environment, robust		   
	estimates store usat_env2
quietly ologit repress i.intervene##c.nationalism, robust		   
	estimates store usat_nat2
	
	
import delimited "can_main.csv", clear varname(1)	
quietly ologit concede i.intervene##c.environment, robust		   
	estimates store cant_env1
quietly ologit concede i.intervene##c.nationalism, robust		   
	estimates store cant_nat1
quietly ologit repress i.intervene##c.environment, robust		   
	estimates store cant_env2
quietly ologit repress i.intervene##c.nationalism, robust		   
	estimates store cant_nat2
	
** generating table A4.1
esttab usat_env1 usat_nat1 cant_env1 cant_nat1 usat_env2 usat_nat2 ///
	   cant_env2 cant_nat2 using "tableA4.1.csv", ///
	   b(2) se(2) obslast stats(ll N) ///
	   nobaselevels label replace nogaps 
	
********************************************************************************
************ Appendix A5: ROBUSTNESS *******************************************
********************************************************************************
   
*** Figure A5.1: Attention Checks
import delimited "usa_main.csv", clear varname(1)
	
quietly ologit concede i.intervene if attention==0, robust
	estimates store us1a
	quietly margins r.intervene, post
	estimates store att1a_us
quietly ologit concede i.intervene if attention==1, robust
	estimates store us1b
	quietly margins r.intervene, post
	estimates store att1b_us	
quietly ologit repress i.intervene if attention==0, robust
	estimates store us2a
	quietly margins r.intervene, post
	estimates store att2a_us
quietly ologit repress i.intervene if attention==1, robust
	estimates store us2b
	quietly margins r.intervene, post
	estimates store att2b_us
	
	
coefplot att1a_us att1b_us, title("Concede to Protesters") ///
	vertical mlabels format(%9.2f) ciopts(recast(rcap)) mlabcol(black) ///
	xlabel(1 `""1" "Strongly" "disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	xtitle("Predicted Respondent Outcomes") ///
	legend(order(2 "Low Attention" 4 "High Attention") rows(1)) ///
	name(att_usa1, replace)

coefplot att2a_us att2b_us, title("Repress Protesters") ///
	vertical mlabels format(%9.2f) ciopts(recast(rcap)) mlabcol(black) ///
	xlabel(1 `""1" "Strongly" "disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	xtitle("Predicted Respondent Outcomes") ///
	legend(order(2 "Low Attention" 4 "High Attention") rows(1))  ///
	name(att_usa2, replace)

graph combine att_usa1 att_usa2, ///
		 xcommon rows(1) name(usa, replace) title("U.S. Sample")

import delimited "can_main.csv", clear varname(1)

quietly ologit concede i.intervene if attention==0, robust
	estimates store can1a
	quietly margins r.intervene, post
	estimates store att1a_can
quietly ologit concede i.intervene if attention==1, robust
	estimates store can1b
	quietly margins r.intervene, post
	estimates store att1b_can	
quietly ologit repress i.intervene if attention==0, robust
	estimates store can2a
	quietly margins r.intervene, post
	estimates store att2a_can
quietly ologit repress i.intervene if attention==1, robust
	estimates store can2b
	quietly margins r.intervene, post
	estimates store att2b_can
	
	
coefplot att1a_can att1b_can, title("Concede to Protesters") ///
	vertical mlabels format(%9.2f) ciopts(recast(rcap)) mlabcol(black) ///
	xlabel(1 `""1" "Strongly" "disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	xtitle("Predicted Respondent Outcomes") ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	legend(order(2 "Low Attention" 4 "High Attention") rows(1)) ///
	name(att_can1, replace)

coefplot att2a_can att2b_can, title("Repress Protesters") ///
	vertical mlabels format(%9.2f) ciopts(recast(rcap)) mlabcol(black) ///
	xlabel(1 `""1" "Strongly" "disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	xtitle("Predicted Respondent Outcomes") ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	legend(order(2 "Low Attention" 4 "High Attention") rows(1)) ///
	name(att_can2, replace)

graph combine att_can1 att_can2, ///
		 xcommon rows(1) name(canada, replace) title("Canada Sample")

graph combine usa canada, xcommon rows(2) xsize(6) ysize(6)


*** Table A5.1: Foreign Interference and Public Support for Protest, by Attention Level
esttab us1a us1b us2a us2b can1a can1b can2a can2b using "tableA5.1.csv", ///
	    b(2) se(2) obslast stats(ll N) keep(1.intervene) ///
	   mtitles("Low" "High" "Low" "High" ///
			   "Low" "High" "Low" "High") ///
	   nobaselevels replace nogaps coeflabels(1.intervene "Interference")


*** Table A5.2: Sample Characteristics by Attention Check

/* Note: The first 2 columns display low and high attention subsets of the
   of the sample, and the third column is the pooled sample average of 
   respondent characteristics by age and gender, which is not included in
   the Figure A5.2 */

import delimited "usa_main.csv", clear varname(1)
tab attention
** Low: 56% High: 44%


tabout age attention using "tableA5.2usa.csv", ptotal(none) ///
	cells(col) style(csv) format(2) h1("Attention Level") ///
	h2(| Low | High | Pooled) replace
tabout female attention using "tableA5.2usa.csv", ptotal(none) ///
	cells(col) style(csv) format(2) h1("Attention Level")   ///
	h2(| Low | High | Pooled) append	
	

proportion age, over(attention)
	estimates store usa1
proportion female, over(attention)
	estimates store usa2	
	
import delimited "can_main.csv", clear varname(1)
tab attention
** Low: 57% High: 43%

* Generating Table A5.2
tabout age attention using "tableA5.2can.csv", ptotal(none) ///
	cells(col) style(csv) format(2) h1("Attention Level") ///
	h2(| Low | High | Pooled) replace
tabout female attention using "tableA5.2can.csv", ptotal(none) ///
	cells(col) style(csv) format(2) h1("Attention Level")   ///
	h2(| Low | High | Pooled) append	
	
*** Figure A5.2: Foreign Interference and Public Support for Protests, by Interfering Country
import delimited "usa_main.csv", clear varname(1)

** Concede
quietly ologit concede i.foreign, robust 
	quietly margins r.foreign if foreign==0 | foreign==1, post
	estimates store usafor1
quietly ologit concede i.foreign, robust 
	quietly margins r.foreign if foreign==0 | foreign==2, post
	estimates store usafor2
quietly ologit concede i.foreign, robust 
	quietly margins r.foreign if foreign==0 | foreign==3, post
	estimates store usafor3	
** Repress
quietly ologit repress i.foreign, robust 
	quietly margins r.foreign if foreign==0 | foreign==1, post
	estimates store usafor4
quietly ologit repress i.foreign, robust 
	quietly margins r.foreign if foreign==0 | foreign==2, post
	estimates store usafor5
quietly ologit repress i.foreign, robust 
	quietly margins r.foreign if foreign==0 | foreign==3, post
	estimates store usafor6	
	
quietly import delimited "can_main.csv", clear varname(1)

** Concede
quietly ologit concede i.foreign, robust 
	quietly margins r.foreign if foreign==0 | foreign==1, post
	estimates store canfor1
quietly ologit concede i.foreign, robust 
	quietly margins r.foreign if foreign==0 | foreign==2, post
	estimates store canfor2
quietly ologit concede i.foreign, robust 
	quietly margins r.foreign if foreign==0 | foreign==3, post
	estimates store canfor3	
** Repress
quietly ologit repress i.foreign, robust 
	quietly margins r.foreign if foreign==0 | foreign==1, post
	estimates store canfor4
quietly ologit repress i.foreign, robust 
	quietly margins r.foreign if foreign==0 | foreign==2, post
	estimates store canfor5
quietly ologit repress i.foreign, robust 
	quietly margins r.foreign if foreign==0 | foreign==3, post
	estimates store canfor6	
	
**** Graphs  
coefplot usafor1 canfor1, vertical ciopts(recast(rcap)) ///
	title("(a) Norway") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly Agree""') xtitle("Concede to Protesters", height(5)) ///
	legend(order(2 "USA" 4 "Canada") rows(1)) ///
	ytitle("") ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	name(for1, replace)
	
coefplot usafor2 canfor2, vertical ciopts(recast(rcap)) ///
	title("(b) Russia") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') xtitle("Concede to Protesters", height(5)) ///
	legend(off)	ytitle("") ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	name(for2, replace)
	
coefplot usafor3 canfor3, vertical ciopts(recast(rcap)) ///
	title("(c) Saudi Arabia") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') xtitle("Concede to Protesters", height(5)) ///
	legend(off) ytitle("") ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	name(for3, replace)

coefplot usafor4 canfor4, vertical ciopts(recast(rcap)) ///
	title("(d) Norway") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') xtitle("Repress Protesters", height(5)) ///
	legend(off) ytitle("") ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	name(for4, replace)
	
coefplot usafor5 canfor5, vertical ciopts(recast(rcap)) ///
	title("(e) Russia") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') xtitle("Repress Protesters", height(5)) ///
	legend(off) ytitle("") ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	name(for5, replace)
	
coefplot usafor6 canfor6, vertical ciopts(recast(rcap)) ///
	title("(f) Saudi Arabia") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') xtitle("Repress Protesters", height(5)) ///
	legend(off) ytitle("") ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	name(for6, replace)

** Graph Combine	
grc1leg2 for1 for2 for3 for4 for5 for6, xcommon rows(2) legendfrom(for1) scale(1.25)

*** TABLE A5.3: FOREIGN INTERFERENCE AND PUBLIC SUPPORT FOR PROTEST MOVEMENTS w/ Controls

* US Data
import delimited "usa_main.csv", clear varname(1)
global controls age i.female i.party education environment nationalism ///
				anti_protest ///
				  

** Main Effects Table
quietly ologit concede i.intel $controls, robust
	estimates store usa1
quietly ologit repress i.intel $controls, robust
	estimates store usa2
quietly ologit concede i.intervene $controls, robust
	estimates store usa3
quietly ologit repress i.intervene $controls, robust
	estimates store usa4
	
	

*** Canada data
import delimited "can_main.csv", clear varname(1)
global controls age i.female i.party education environment nationalism ///
				anti_protest 

** Main Effects Table
quietly ologit concede i.intel $controls, robust
	estimates store can1
quietly ologit repress i.intel $controls, robust
	estimates store can2
quietly ologit concede i.intervene $controls, robust
	estimates store can3
quietly ologit repress i.intervene $controls, robust
	estimates store can4
	
** Label continuous variables
label variable education "Education"
label variable environment "Environment"
label variable nationalism "Nationalism"
label variable anti_protest "Protest Attitudes"	
	
** generating table A5.3
esttab usa1 usa2 usa3 usa4 can1 can2 can3 can4 using "tableA5.3.csv", ///
	   b(2) se(2) obslast stats(ll N) ///
	   nobaselevels label replace nogaps ///
	   coeflabels(2.party "Democrats (Liberals)" ///
				  3.party "Republicans (Conservatives)" 4.party "NDP" ///
				  5.party "Green Party" 1.female "Female") 
				  			  

*** TABLE A5.4: Foreign Interference and Public Support for Protests Without Controls
import delimited "usa_main.csv", clear varname(1)

quietly ologit concede i.intervene, robust
	estimates store usa1
quietly ologit repress i.intervene, robust
	estimates store usa2	
quietly ologit concede i.intel, robust
	estimates store usa3
quietly ologit repress i.intel, robust
	estimates store usa4	
		
	

import delimited "can_main.csv", clear varname(1)

quietly ologit concede i.intervene, robust
	estimates store can1
quietly ologit repress i.intervene, robust
	estimates store can2
quietly ologit concede i.intel, robust
	estimates store can3
quietly ologit repress i.intel, robust
	estimates store can4		
	
** generating table A5.4
esttab usa3 usa4 usa1 usa2 can3 can4 can1 can2 using "tableA5.4.csv", ///
	   b(2) se(2) obslast stats(ll N) ///
	   mtitles("Concede" "Repress" "Concede" "Repress" ///
			   "Concede" "Repress" "Concede" "Repress") ///
	   nobaselevels replace nogaps keep(1.intervene 1.intel 2.intel) ///
	   coeflabels(1.intervene "Interference" 1.intel "75% Intel" ///
				  2.intel "100% Intel")
	
	
*** TABLE A5.5: Conditional Effects of Foreign Interference (U.S. Survey)
import delimited "usa_main.csv", clear varname(1)
** Conditional Effects for Concede
quietly ologit concede i.foreign, robust
	estimates store usa_for1
quietly ologit concede i.timing, robust
	estimates store usa_tim1
quietly ologit concede i.support, robust
	estimates store usa_sup1
quietly ologit concede i.intervene##i.outsider, robust
	estimates store usa_out1

** Conditional Effects for Repress	
quietly ologit repress i.foreign, robust
	estimates store usa_for2
quietly ologit repress i.timing, robust
	estimates store usa_tim2
quietly ologit repress i.support, robust
	estimates store usa_sup2
quietly ologit repress i.intervene##i.outsider, robust
	estimates store usa_out2

	
** generating table A5.5
esttab usa_for1 usa_tim1 usa_sup1 usa_out1 ///
	   usa_for2 usa_tim2 usa_sup2 usa_out2 using "tableA5.5.csv", ///
	   b(2) se(2) obslast stats(ll N) ///
	   nobaselevels label replace nogaps ///
	   mtitles("Concede" "Concede" "Concede" "Concede" ///
			   "Repress" "Repress" "Repress" "Repress") ///
	   coeflabels(1.foreign "Norway" 2.foreign "Russia" ///
				  3.foreign "Saudi Arabia" 1.timing "Before" ///
				  2.timing "After" 1.support "Financial" ///
				  2.support "Training") 	

*** TABLE A5.6: Conditional Effects of Foreign Interference (U.S. Survey)
import delimited "usa_main.csv", clear varname(1)
global controls age i.female i.party education environment nationalism ///
				anti_protest 
  

** Conditional Effects for Concede
quietly ologit concede i.foreign $controls, robust
	estimates store usa_for1
quietly ologit concede i.timing $controls, robust
	estimates store usa_tim1
quietly ologit concede i.support $controls, robust
	estimates store usa_sup1
quietly ologit concede i.intervene##i.outsider $controls, robust
	estimates store usa_out1

** Conditional Effects for Repress	
quietly ologit repress i.foreign $controls, robust
	estimates store usa_for2
quietly ologit repress i.timing $controls, robust
	estimates store usa_tim2
quietly ologit repress i.support $controls, robust
	estimates store usa_sup2
quietly ologit repress i.intervene##i.outsider $controls, robust
	estimates store usa_out2

label variable intervene "Interference"
label variable outside "Out-group"
label variable nationalism "Nationalism"
label variable environment "Environment"
label variable anti_protest "Protest Attitudes"
 	
** generating table A5.6
esttab usa_for1 usa_tim1 usa_sup1 usa_out1 ///
	   usa_for2 usa_tim2 usa_sup2 usa_out2 using "tableA5.6.csv", ///
	   b(2) se(2) obslast stats(ll N) ///
	   nobaselevels label replace nogaps ///
	   mtitles("Concede" "Concede" "Concede" "Concede" ///
			   "Repress" "Repress" "Repress" "Repress") ///
	   coeflabels(1.foreign "Norway" 2.foreign "Russia" ///
				  3.foreign "Saudi Arabia" 1.timing "Before" ///
				  2.timing "After" 1.support "Financial" ///
				  2.support "Training") 
				  
*** Table A5.7: Conditional Effects of Foreign Interference (Canada Survey) 				  
				  
** Canadian Data
import delimited "can_main.csv", clear varname(1)

** Conditional Effects for Concede
quietly ologit concede i.foreign, robust
	estimates store can_for1
quietly ologit concede i.timing, robust
	estimates store can_tim1
quietly ologit concede i.support, robust
	estimates store can_sup1
quietly ologit concede i.intervene##i.outside, robust
	estimates store can_out1

** Conditional Effects for Repress	
quietly ologit repress i.foreign, robust
	estimates store can_for2
quietly ologit repress i.timing, robust
	estimates store can_tim2
quietly ologit repress i.support, robust
	estimates store can_sup2
quietly ologit repress i.intervene##i.outside, robust
	estimates store can_out2
							  
** generating table A5.7
esttab can_for1 can_tim1 can_sup1 can_out1 ///
	   can_for2 can_tim2 can_sup2 can_out2 using "tableA5.7.csv", ///
	   b(2) se(2) obslast stats(ll N) ///
	   nobaselevels label replace nogaps ///
	   mtitles("Concede" "Concede" "Concede" "Concede" ///
			   "Repress" "Repress" "Repress" "Repress") ///
	   coeflabels(1.foreign "Norway" 2.foreign "Russia" ///
				  3.foreign "Saudi Arabia" 1.timing "Before" ///
				  2.timing "After" 1.support "Financial" ///
				  2.support "Training") 
				  		
*** Table A5.8: Conditional Effects of Foreign Interference (Canada Survey) 				  	
** Canadian Data
import delimited "can_main.csv", clear varname(1)

global controls age i.female i.party education environment nationalism ///
		        anti_protest 

** Conditional Effects for Concede
quietly ologit concede i.foreign $controls, robust
	estimates store can_for1
quietly ologit concede i.timing $controls, robust
	estimates store can_tim1
quietly ologit concede i.support $controls, robust
	estimates store can_sup1
quietly ologit concede i.intervene##i.outside $controls, robust
	estimates store can_out1

** Conditional Effects for Repress	
quietly ologit repress i.foreign $controls, robust
	estimates store can_for2
quietly ologit repress i.timing $controls, robust
	estimates store can_tim2
quietly ologit repress i.support $controls, robust
	estimates store can_sup2
quietly ologit repress i.intervene##i.outside $controls, robust
	estimates store can_out2

label variable intervene "Interference"
label variable outside "Out-group"
label variable nationalism "Nationalism"
label variable environment "Environment"
label variable anti_protest "Protest Attitudes"	
	
** generating table A5.8
esttab can_for1 can_tim1 can_sup1 can_out1 ///
	   can_for2 can_tim2 can_sup2 can_out2 using "tableA5.8.csv", ///
	   b(2) se(2) obslast stats(ll N) ///
	   nobaselevels label replace nogaps ///
	   mtitles("Concede" "Concede" "Concede" "Concede" ///
			   "Repress" "Repress" "Repress" "Repress") ///
	   coeflabels(1.foreign "Norway" 2.foreign "Russia" ///
				  3.foreign "Saudi Arabia" 1.timing "Before" ///
				  2.timing "After" 1.support "Financial" ///
				  2.support "Training") 
		  
*** Figure A5.3: Foreign Interference, Protest Support, by Protest Group
import delimited "usa_main.csv", clear varname(1)

quietly ologit concede i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=0) post
	estimates store gp1
quietly ologit concede i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=1) post
	estimates store blm1
quietly ologit concede i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=2) post
	estimates store naacp1	
quietly ologit concede i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=3) post
	estimates store sierra1 

quietly ologit repress i.intervene i.pgroups, robust
	quietly margins r.intervene, at(pgroups=0) post
	estimates store gp2
quietly ologit repress i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=1) post
	estimates store blm2
quietly ologit repress i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=2) post
	estimates store naacp2	
quietly ologit repress i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=3) post
	estimates store sierra2
	
coefplot gp1 sierra1 blm1 naacp1, bylabel("(a) Concede to Protesters") || ///
		 gp2 sierra2 blm2 naacp2, bylabel("(b) Repress Protesters") ///
		 vertical ciopts(recast(rcap)) ///
		 xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') ///
xtitle("Concede to Protesters                               Repress Protesters", height(5)) ///
		 legend(order(2 "Greenpeace" 4 "Sierra Club" 6 "BLM" 8 "NAACP")) ///
		 ytitle("Marginal Treatment Effect" "of Foreign Interference") ///
		 yline(0, lpattern(dash) lcolor(black*.5)) ///
		 title("U.S. Survey") ///
		 name(us_pgroups, replace)
	
* Canadian Data	
import delimited "can_main.csv", clear varname(1)
rename pgroup pgroups

quietly ologit concede i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=1) post
	estimates store afn1
quietly ologit concede i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=2) post
	estimates store mnc1
quietly ologit concede i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=3) post
	estimates store gp3	
quietly ologit concede i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=4) post
	estimates store nc1

quietly ologit repress i.intervene i.pgroups, robust
	quietly margins r.intervene, at(pgroups=1) post
	estimates store afn2
quietly ologit repress i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=2) post
	estimates store mnc2
quietly ologit repress i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=3) post
	estimates store gp4
quietly ologit repress i.intervene##i.pgroups, robust
	quietly margins r.intervene, at(pgroups=4) post
	estimates store nc2	
	
coefplot gp3 nc1 afn1 mnc1, bylabel("(c) Concede to Protesters") || ///
		 gp4 nc2 afn2 mnc2, bylabel("(d) Repress Protesters") ///
		 vertical ciopts(recast(rcap)) ///
		 xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') ///
		 xtitle("Concede to Protesters                               Repress Protesters", height(5)) ///
		 legend(order(2 "Greenpeace" 4 "Nature Canada" 6 "Indigenous Group 1" 8 "Indigenous Group 2")) ///
		 ytitle("Marginal Treatment Effect" "of Foreign Interference") ///
		 yline(0, lpattern(dash) lcolor(black*.5))	///
		 title("Canada Survey") ///
		 name(can_pgroups, replace)
	
	
graph combine us_pgroups can_pgroups, rows(2) xsize(4) ysize(4.5)	  
			  
*** Table A5.9: Foreign Interference, Protest Support, by Protest Group		  
	
import delimited "usa_main.csv", clear varname(1)
	replace pgroups = 4 if pgroups==3
	replace pgroups = 3 if pgroups==2
	replace pgroups = 2 if pgroups==1
	replace pgroups = 1 if pgroups==0
	
quietly ologit concede i.intervene##i.pgroups, robust	
		estimates store pusa1
quietly ologit repress i.intervene##i.pgroups, robust	
		estimates store pusa2
				
import delimited "can_main.csv", clear varname(1)
	rename pgroup pgroups
	
quietly ologit concede i.intervene##i.pgroups, robust	
		estimates store pcan1
quietly ologit repress i.intervene##i.pgroups, robust	
		estimates store pcan2		
		
esttab pusa1 pusa2 pcan1 pcan2 using "tableA5.10.csv", ///
	   b(2) se(2) obslast stats(ll N) ///
	   nobaselevels label replace nogaps  ///
	   coeflabels(2.pgroups "Sierra Club (Nature Canada)" ///
				  3.pgroups "BLM (Indigenous Group 1)" ///
				  4.pgroups "NAACP (Indigenous Group 2)" ///
				  1.intervene "Interference") 	   
				  			  		
		
		
*** Figure A5.4: Effect of Foreign Interference on Environmental Preferences
** USA
import delimited "usa_main.csv", clear varname(1)

quietly ologit frack i.intervene, robust 
	quietly margins r.intervene, post
	estimates store usalong1
quietly ologit damage i.intervene, robust 
	quietly margins r.intervene, post
	estimates store usalong2

** Canada
import delimited "can_main.csv", clear varname(1)

quietly ologit frack i.intervene, robust 
	quietly margins r.intervene, post
	estimates store canlong1
quietly ologit damage i.intervene, robust 
	quietly margins r.intervene, post
	estimates store canlong2
	
coefplot usalong1  canlong1, bylabel("(a) Damage from Fracking") || ///
		 usalong2 canlong2, bylabel("(b) Damage from Pipeline Construction") ///
		 vertical ciopts(recast(rcap)) ///
		 xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') ///
		 xtitle("Should Refrain from Fracking                          Avoid Building New Pipelines", height(5)) ///
		 legend(order(2 "USA" 4 "Canada")) ///
		 ytitle("Marginal Treatment Effect" "of Foreign Interference") ///
		 yline(0, lpattern(dash) lcolor(black*.5))
		   

***	Table A5.10: Foreign Interference and Public Support for Protest (More Robustness)	  

* US Data
import delimited "usa_main.csv", clear varname(1)
global controls1 saudi norway russia white_nationalist i.white income gov cov1-cov4 ///
				 age i.female i.party education environment nationalism ///
				 anti_protest 

** Main Effects Table
quietly ologit concede i.intervene $controls1, robust
	estimates store usa1
quietly ologit repress i.intervene $controls1, robust
	estimates store usa2
	
	

*** Canada data
import delimited "can_main.csv", clear varname(1)
global controls1 saudi norway russia ethnocentrism i.white income federal ///
				 cov1-cov4 age i.female i.party education environment ///
				 nationalism anti_protest 

** Main Effects Table
quietly ologit concede i.intervene $controls1, robust
	estimates store can1
quietly ologit repress i.intervene $controls1, robust
	estimates store can2
	
** Label continuous variables
label variable education "Education"
label variable environment "Environment"
label variable nationalism "Nationalism"
label variable anti_protest "Protest Attitudes"	
label variable ethnocentrism "Ethnocentrism"	

** generating table A5.9
esttab usa1 usa2 can1 can2 using "tableA5.9.csv", ///
	   b(2) se(2) obslast stats(ll N) ///
	   nobaselevels label replace nogaps ///
	   coeflabels(2.party "Democrats (Liberals)" ///
				  3.party "Republicans (Conservatives)" 4.party "NDP" ///
				  5.party "Green Party" 1.female "Female") 
				  			  